package com.mcptt.config.group.sub;

import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.product.log.Log;

public class PreferredVoiceEncodings {
	public static final String Name = "preferred-voice-encodings";
	private static final String Namespace_Mcpttgi = "mcpttgi";
	private static final String Name_Encoding = "encoding";
	private static final String Name_Name = "name";
	private List<String> encodingList = null;

	public void parse(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		encodingList = new Vector<String>();
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);

			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			if(name.equals(Name_Encoding))
			{
				String value = subElem.getAttributeValue(Name_Name);
				encodingList.add(value);
			}
		}  
	}

	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(Namespace_Mcpttgi).append(":").append(Name).append(">");
		for(Iterator<String> itor = encodingList.iterator(); itor.hasNext();)
		{
			String value = itor.next();
			strBuf.append("<").append(Namespace_Mcpttgi).append(":").append(Name_Encoding).append(" ").append(Name_Name).append("=\"").append(value).append("\"/>").append("\r\n");
		}
		strBuf.append("</").append(Namespace_Mcpttgi).append(":").append(Name).append(">");

		return strBuf.toString();
	}
}
